import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    //保存token验证是否登录
    token:'',
    // 保存登录用户信息
    user:{
      account:'xieqian',
      password:'xieqian'
    },
    // 保存当前播放音乐的详情
      thisMusic:{},
    // 保存所有播放过的音乐
    allMusic:[],
    // 保存收藏的音乐列表
    collectionMusicList:[],
    // 保存编辑信息
    edit:{
      username:'小谢同学',
      introduction:'无',
      region:'湖南省株洲市'
    }
  },

  mutations: {
    turnmusicurl(state,payload){
      state.thisMusic=payload;
    },
    addAllMusic(state,payload){
      state.allMusic.push(payload);
      let list=state.allMusic;
      function unique (list) {
        return Array.from(new Set(list))
      };
      state.allMusic=unique(list)
    },
    addCollectionMusicList(state,payload){
      let list=state.collectionMusicList;
         for(let i=0;i<state.allMusic.length;i++){
           if(state.allMusic[i].id===state.thisMusic.id){
             state.collectionMusicList.push(state.allMusic[i])
           }
      }
        function unique (list) {
          return Array.from(new Set(list))
        };
        state.collectionMusicList=unique(state.collectionMusicList)
    },
    addtoken(state,payload){
      state.token='123456'
    },
    addEdit(state,payload){
      state.edit.introduction=payload.introduction;
      state.edit.username=payload.username;
      state.edit.region=payload.region;
    }
  },
  actions: {
  },
  modules: {
  }
})
